-
Notifications
You must be signed in to change notification settings - Fork 899
Add a bunch of stuffs to Index.Remove() #398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm strongly in favor of changing the remove semantics to allow for In doing this, we should probably start calling |
@@ -194,6 +194,50 @@ private static void InvalidMoveUseCases(string sourcePath, FileStatus sourceStat | |||
} | |||
} | |||
|
|||
public void CanRemoveAFolderThroughUsageOfPathspecs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we missing a [Fact]
attribute here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a matter of fact, yes we do!
@yishaigalatzer @anaisamp This PR should fix some of your requests. |
} | ||
|
||
[Fact] | ||
public void RemovingAInvalidFileThrows() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we now have only one case, could you please update the name of the test to actually express what kind of state is being invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we now have only one case
Or maybe are we missing some of them. What about FileStatus.TypeChanged
for instance?
Thank you so much! Good job, you guys are awesome! :) |
Here is an update:
Missing:
@nulltoken would it be possible to address the first 2 points in another PR? |
Cool with me 👍
@yishaigalatzer I believe this should fix #325 as well. |
I will work on the |
} | ||
|
||
if (dic.Count == 0) | ||
foreach (string path in pathsList.Where(p => Directory.Exists(Path.Combine(wd, p)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly a premature optimization, but checking Directory.Exists()
twice for every entry in pathsList
seems like it's worth avoiding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed!
👍
|
Note: it means that the paths passed to Remove() are pathspecs, and thus behavior has been aligned with Stage()/Unstage() => calling Remove() by passing a pathspec which doesn't match any paths doesn't throw anymore (breaking change).
This makes the behavior fully consistent with Index.Stage()/Unstage().
Lots of test cases added, to mimic git rm --cached behavior.
Beware, this is supported only for files which exist in the workdir (cf. comment in code). Partially fixes #325
❤️ |
Ok, time to look back at what we do in this PR. There is one corner-case with the current approach: as we rely on Note: with a Another option would be to consider that this whole logic should be part of libgit2, but I'm afraid this might be considered a bit too high-level. @carlosmn Thoughts? All in all, I think I would advocate merging this PR as is, and build from there. I think the tests are quite clear and express clearly the expectations, so should we refactor we have our bases covered. |
Does this mean that I can't call I'm not sure that's such a corner case, actually; I added So having this would be very beneficial for us - it would be one less hack to drag forward. I think that a flag to the index iterator to include high-stage entries may not be inappropriate if that would be helpful? |
Yes 😞
Well, at the moment you can still do it, just not when the file is missing from the workdir.
I'm afraid this won't be enough. From what I understand so far, the semantics returned by Edit (proposal): what about letting the |
What can libgit2 do differently to enhance this scenario?
I don't think you should go back to I'm okay with an explicit |
Unless someone strongly opposes, I'm going to merge this as is later today. @yorah Could you please create an issue so we that we track this?
|
AMAZING work! Merged. |
With this PR, it is now possible to:
ExplicitPathsOptions
toIndex.Remove()
git rm --cached
)This fixes #270 and #327.
Please note that the behavior is now consistent with
Index.Stage()/Unstage()
:ExplicitPathsOptions
) which don't match any files will throw.This is a breaking change.